﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace _40_C_中两种常用实现单例模式的方式
{
    internal class Singleton2
    {
        private static Singleton2 singleton2 = null;

        private static readonly object _lock = new object();

        public Singleton2()
        {

            Name = "李四";
        }

        public static Singleton2 Instance
        {
            get
            {
                if (singleton2 == null)
                {
                    lock (_lock)//防止多线程
                    {
                        if (singleton2 == null)
                        {
                            singleton2 = new Singleton2();
                        }
                        return singleton2;
                    }
                }
                return singleton2;

            }
        }
        public string Name { get; set; }

        public void show()
        {

            Console.WriteLine("第二种单例方式");
        }
    }
}
